# Contributor: Mark Pashmfouroush <mark@markpash.me>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Mark Pashmfouroush <mark@markpash.me>
pkgname=coredns
pkgver=1.11.1
pkgrel=6
pkgdesc="fast and flexible DNS server"
url="https://github.com/coredns/coredns"
license="Apache-2.0"
arch="all"
makedepends="go unbound-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="https://github.com/coredns/coredns/archive/v$pkgver/coredns-$pkgver.tar.gz
	coredns.confd
	coredns.initd
	coredns.logrotated
	ensure-cgo.patch
	plugin.cfg.enabled
	"
options="net" # for downloading Go modules

# secfixes:
#   1.9.3-r0:
#     - CVE-2022-27191
#     - CVE-2022-28948

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare
	cp "$srcdir"/plugin.cfg.enabled "$builddir"/plugin.cfg
}

build() {
	CGO_ENABLED=1 make
}

check() {
	cd "$builddir"/request; go test ./...
	cd "$builddir"/core; go test ./...
	cd "$builddir"/coremain; go test ./...
	cd "$builddir"/plugin; go test ./...
}

package() {
	install -Dm755 coredns "$pkgdir"/usr/bin/coredns

	install -Dm755 "$srcdir"/coredns.initd "$pkgdir"/etc/init.d/coredns
	install -Dm644 "$srcdir"/coredns.confd "$pkgdir"/etc/conf.d/coredns
	install -Dm 644 "$srcdir"/coredns.logrotated "$pkgdir"/etc/logrotate.d/coredns

	install -d "$pkgdir"/etc/coredns
	install -d "$pkgdir"/var/log/coredns
}

sha512sums="
f8752811e9e7913311f47ae13f35c755ac86ea240572be1c1dabc1712b6c42380c60ac385fa9573c77d6fcf4c144df2bc00574f18e8d7b70da21ed8ae4fb87cd  coredns-1.11.1.tar.gz
90300a3035b00b58f362b2c12dfaeee21b889e10e90600523b5785c907dfbd7e515c3269dd29a9d4c758990e78ede8343edfac0bc022bd3a23652543ba2d42d3  coredns.confd
802ac66ea27ac71001706b0994a579e0ab3f608a89d0a03f92490f4b73c4bd202745fd13b34d957122c8f1439be2709604c7931ff2a7be003c573e746c9d98b9  coredns.initd
c697c08c3b1153ae224a1eeb3521f9ee594de4852bc6ef78d94dc7f6f680517659a653ab5c13ea03918deb79e6654ef11512ba4c90fe06ea4591fefbab876ece  coredns.logrotated
9f2c08750b42f0901bc190a4c829a5a003e4c3aa9bd55e9a2f37f68f446cdd15b60227b7d2381d85b49674580f7c0206af76345d6dd5160401772c3efbf50ab6  ensure-cgo.patch
4cce898cfe2bd9891e4ac638c30bc04cffe560044240dd608fa64ffdf6320d488da0d0505920889db41e25f592b74b759fb01830528c46bea6adb37919eca629  plugin.cfg.enabled
"
